//
//  SGActivityGroundTableView.m
//  SemiGroup
//
//  Created by 陈无忌 on 12/10/15.
//  Copyright © 2015 陈无忌. All rights reserved.
//

#import "SGActivityGroundTableView.h"

@interface SGActivityGroundTableView()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) NSMutableArray *displayArray;
@property (nonatomic) TABLEVIEWDATATYPE viewType;

@property (nonatomic) BOOL isRefresh;
@property (nonatomic) BOOL canLoadMore;

@end

@implementation SGActivityGroundTableView


- (void)awakeFromNib{
    self.delegate = self;
    self.dataSource = self;
    self.tableFooterView = [UIView new];
    //register cell
    [self registerNib:[UINib nibWithNibName:@"SGActivityCell" bundle:nil] forCellReuseIdentifier:@"SGHomePageActivityTableViewCell"];
    //default refresh status
    self.isRefresh = NO;
    self.canLoadMore = YES;
    //refresh control
    [self addHeaderWithTarget:self action:@selector(headerRereshing)];
    [self addFooterWithTarget:self action:@selector(footerRereshing)];
}


#pragma mark - Public Method
- (void)loadDataWithType:(TABLEVIEWDATATYPE)type{
    self.viewType = type;
    
}

#pragma mark - Refresh Method

- (void)headerRereshing{
    if (!self.isRefresh) {
        self.isRefresh = YES;
        
    }
}

- (void)footerRereshing{
    if (self.canLoadMore) {
        
    }else{
        
    }
}

#pragma mark - Table view datasource
- (NSInteger)numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.displayArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    SGActivity *activity = [self.displayArray objectAtIndex:indexPath.row];
    SGHomePageActivityTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SGHomePageActivityTableViewCell"];
    [cell configCellWithActivity:activity];
    return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    SGActivity *activity = [self.displayArray objectAtIndex:indexPath.row];
    if (self.selectDelegate && [self.selectDelegate respondsToSelector:@selector(activitySelect:)]) {
        [self.selectDelegate activitySelect:activity];
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
